
component  extends="ModelGlue.gesture.controller.Controller" output="false" beans="core"
{
	public ModelGlue.gesture.controller.Controller function init( required Any modelGlue){
		
		super.init( arguments.modelGlue );
		
		return this;
	}
	
	public ModelGlue.Core.Event function new( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		
		arguments.event.setValue( 'Permission', Permission );
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function create( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var validator = service.getValidator();
		
		arguments.event.makeEventBean( Permission );
		
		arguments.event.setValue( 'Permission', Permission );
		
		validator.validate( Permission );
			
		if( validator.hasErrors() ){
		
			arguments.event.setValue( 'error', validator.getErrors() );
			
			arguments.event.addResult( 'save.failure' );
		
		}else{
			
				service.create( Permission );
				
				arguments.event.addResult( 'save.success' );
			
		}
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function update( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var validator = service.getValidator();
		
		arguments.event.makeEventBean( Permission );
		
		arguments.event.setValue( 'Permission', Permission );
		
		validator.validate( Permission );
			
		if( validator.hasErrors() ){
		
			arguments.event.setValue( 'error', validator.getErrors() );
			
			arguments.event.addResult( 'save.failure' );
		
		}else{
			
				service.update( Permission );
				
				arguments.event.addResult( 'save.success' );
			
		}
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function save( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var validator = service.getValidator();
		
		arguments.event.makeEventBean( Permission );
		
		arguments.event.setValue( 'Permission', Permission );
		
		validator.validate( Permission );
			
		if( validator.hasErrors() ){
		
			arguments.event.setValue( 'error', validator.getErrors() );
			
			arguments.event.addResult( 'save.failure' );
		
		}else{
			
				service.save( Permission );
				
				arguments.event.addResult( 'save.success' );
			
		}
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function delete( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var val = "";
		
		arguments.event.makeEventBean( Permission );
		
		arguments.event.setValue( 'Permission', Permission );
		
		service.delete( Permission );
									
		arguments.event.addResult( 'delete.success' );
		
		return arguments.event;
	}	
	
	
	public ModelGlue.Core.Event function get( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var result = "";
		
		arguments.event.makeEventBean( Permission );
		
		result = service.get( Permission );
									
		arguments.event.setValue( 'Permission', result );
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function list( required Any event ){
		
		var service = beans.core.getService( 'Permission' );
		var Permission = service.new();
		var result = "";
		
		result = service.getPermissions( Permission );
									
		arguments.event.setValue( 'Permission.list', result );
		
		return arguments.event;
	}

}
